package com.itcast.demo_one

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class ButtonActivity : AppCompatActivity(), View.OnClickListener {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_button)

        // 1. 获取B按钮
       /* val btn2 = findViewById<Button>(R.id.btn2)
        btn2.setOnClickListener {
            Toast.makeText(this, "点击了B按钮", Toast.LENGTH_SHORT).show()
        }*/

        // 把三个按钮的点击事件，统一交给ButtonActivity处理
        val btn1 = findViewById<Button>(R.id.btn1)
        val btn2 = findViewById<Button>(R.id.btn2)
        val btn3 = findViewById<Button>(R.id.btn3)
        btn1.setOnClickListener(this)
        btn2.setOnClickListener(this)
        btn3.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.btn1 -> {
                Toast.makeText(this, "点击了A按钮", Toast.LENGTH_SHORT).show()
            }
            R.id.btn2 -> {
                Toast.makeText(this, "点击了B按钮", Toast.LENGTH_SHORT).show()
            }
            R.id.btn3 -> {
                Toast.makeText(this, "点击了C按钮", Toast.LENGTH_SHORT).show()
            }
        }
    }

    /*fun onClickMe(view: View){
       Toast.makeText(this, "点击了A按钮", Toast.LENGTH_SHORT).show()
    }*/
}